package com.ithuang.websocket.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.ithuang.websocket.config.R;
import com.ithuang.websocket.config.User;
import com.ithuang.websocket.util.jwtUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@ResponseBody
public class teController {
//    @RequestHeader("token") String authorization
    @RequestMapping("/login")
    public R te(@RequestBody User user) {
//        System.out.println(user.getUserName()); // 建议使用 println 以避免潜在的编码问题

        Map<String, String> payload = new HashMap<>();
        payload.put("name",user.getUserName());
String token=com.ithuang.websocket.util.jwtUtils.getToken(payload);
//System.out.print(token);
//        DecodedJWT verify = null;
//        try {
//            verify = jwtUtils.verify(token);
//        } catch (jwtUtils.JWTVerificationException e) {
//            throw new RuntimeException(e);
//        }
//        log.info("用户id：[{}]",verify.getClaim("username").asString());
//System.out.print(verify.getClaim("name").asString()+"username");
        return  new R(token);
    }


    @RequestMapping("/home")
    public R te(@RequestHeader("token") String token){
//        System.out.print("看看"+token);
        return new R("123");
    }
}